package com.example.administrator.myapplication.fragment;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;

import android.text.LoginFilter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.myapplication.R;
import com.example.administrator.myapplication.activity.loginActivity;

public class MyFragment extends Fragment {
    ImageView imageView;
      TextView textView;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=  inflater.inflate(R.layout.fragment_my, container, false);
        imageView =view.findViewById(R.id.img);
        textView=view.findViewById(R.id.tv_username);
        imageView .setOnClickListener(new  View.OnClickListener(){

            @Override
            public void onClick(View view) {
                Log.i("MyFragment", "login ");
                SharedPreferences sharedPreferences=getActivity().getSharedPreferences("login",Context.MODE_PRIVATE);
                boolean islogin=sharedPreferences.getBoolean("islogin",false);

                 islogin=sharedPreferences.getBoolean("islogin",false);


                if (islogin){
                    Toast.makeText(getActivity(),"已经登录过了",Toast.LENGTH_LONG).show();


                    return;
                }
                Intent itent =new Intent(getActivity(),loginActivity.class);
                startActivity(itent);
            }
        });
        return  view;
    }


    @Override
    public void onResume() {
        SharedPreferences sharedPreferences=getActivity().getSharedPreferences("login",Context.MODE_PRIVATE);
        String  username =sharedPreferences.getString("username","点击登录");
        textView.setText(username);
        super.onResume();
    }
}
